﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：武双 
    //
    // 文件名：BulidPaymentManageConfirmed.aspx.cs
    // 文件功能描述：结算管理：已确认
    // 创建标识：武双2009-05-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Hospitals.Collection
{
    public partial class BulidPaymentManageConfirmed : BasePage
    {
        public BulidPaymentManageConfirmed()
        {
            this.ModuleNo = Module.结算单管理.ToString();
        }

        int totalDrugrecord = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            QueryData();
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            QueryData();
        }

        protected void QueryData()
        {
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            HZ.DrugTrade.Model.Query.InvoicePay qryWhere = new HZ.DrugTrade.Model.Query.InvoicePay();
            qryWhere.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            //qryWhere.InvoicePayNo = txtProjectNo.Text.Trim();
            qryWhere.InvoicePayName = txtDistriPlanName.Text.Trim();
            qryWhere.CompanyName_PS = lblCompanyName.Text.Trim();
            qryWhere.PayStatus = 1;
            qryWhere.SortFields = "InvoicePayTime DESC";
            IList<Model.View.InvoicePay> lstInvoicePay = new List<Model.View.InvoicePay>();
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            lstInvoicePay = iPurchase.GetTotalInvoicePayByWhere(qryWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalDrugrecord);
            gvwProcurementProjectList.DataSource = lstInvoicePay;
            gvwProcurementProjectList.AutoGenerateColumns = false;
            gvwProcurementProjectList.DataBind();
            AspNetPager1.RecordCount = totalDrugrecord;

        }

        protected void gvwProcurementProjectList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //删除结算单
            if (e.CommandName.Equals("Del"))
            {
                HZ.DrugTrade.Model.InvoicePay qryWhere = new HZ.DrugTrade.Model.InvoicePay();
                qryWhere.InvoicePaySerialID = e.CommandArgument.ToString();
                IBLL_Purchase iPurchase = Factory.BLL_Purchase();
                int nSuccess = iPurchase.DeleteInvoicePay(qryWhere);
                if (nSuccess == 1)
                {
                    HZ.Web.WebUtil.Alert("结算单删除成功!",this);
                    HZ.Web.WebUtil.RedirectByScript("BulidPaymentManage.aspx");
                    return;
                }
                else
                {
                    HZ.Web.WebUtil.Alert("结算单删除失败!",this);
                    return;
                }
            }
        }

        /// <summary>
        /// 绑定结算单状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwProcurementProjectList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblPayStatus = e.Row.FindControl("lblPayStatus") as Label;
                if (lblPayStatus.Text == "0")
                {
                    lblPayStatus.Text = "未确认";
                }
                else if (lblPayStatus.Text == "1")
                {
                    //已确认的结算单不具有修改和删除功能
                    lblPayStatus.Text = "已确认";
                }
            }
        }
    }
}
